@extends('admin.base')
@section('title', '商品列表')
@section('content')
<div id="main">
 <div class="layui-card">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/group/index')}}" style="cursor:pointer;" ><cite>拼团列表</cite></a>;
            </span>
        </div>
    </fieldset>
    <div class="layui-card-header">
      <div>
        <span class="pull-left">
          <div class="layui-form">
            <div class="layui-form-item">
              <div class="layui-inline" style="width:100%">     
                <!-- <label class="layui-form-label">商品ID</label>
                <div class="layui-input-inline" style="width:120px">
                    <input type="text" class="layui-input" id="" name="sub_gid" value="{{ isset($request['gid']) ? $request['gid'] : '' }}"  placeholder="请输入商品ID">
                </div> -->
                <label class="layui-form-label">商品名</label>
                <div class="layui-input-inline" style="width:120px">
                    <input type="text" class="layui-input" id="" name="sub_gname" value="{{ isset($request['gname']) ? $request['gname'] : '' }}"  placeholder="请输入商品名">
                </div>
                
                <label class="layui-form-label" style="width:100px">拼团时间</label>
                <div class="layui-input-inline" style="width:150px;">
                    <input type="text" class="layui-input" id="test1" name='month' value="{{$request['month']}}" readonly>
                </div>
                <button class="layui-btn" lay-submit lay-filter="selectsub" style="margin-bottom:10px">搜索</button>
              </div>
            </div>
          </div>
        </span>
      </div>
    </div>

    <div class="layui-card-body">
        <style>
            table tr td.tc,table tr th.tc {
                text-align: center;
                cursor:default;
            }
        </style>
        <table class="layui-table" lay-even lay-size="">
            <colgroup>
                <col width="">
                <col width="">
                <col width="">
                <col width="">
                <col width="">
                <col width="">
            </colgroup>
            <thead>
                <tr>
                    <th class="tc">ID</th>
                    <th class="tc">商品名</th>
                    <th class="tc">商品图片</th>
                    <th class="tc">规格</th>
                    <!-- <th class="tc">成本价</th> -->
                    <th class="tc">销售价</th>
                    <th class="tc">利润</th>
                    <th class="tc">拼团数</th>
                    <!-- <th class="tc">本次参团数</th> -->
                    <th class="tc">股票</th>
                    <th class="tc">轮次</th>
                    <th class="tc">开始日期</th>
                    <th class="tc">结束日期</th>
                    <th class="tc">状态</th>
                    <th class="tc">创建时间</th>
                    <th class="tc">操作</th>
                </tr>
                <tbody>
                    @if($list->isEmpty())
                        <tr>
                            <td colspan="19" class="tc">暂无数据</td>
                        </tr>
                    @else
                        @foreach ($list as $v)
                           <tr>
                            
                                <td class="tc">{{$v['id']}}</td>
                                <td class="tc">{{$v['name']}}</td>
                                <td class="tc">
                                    <img src="{{$v['picname']}}" height="100px">
                                </td>
                               <td class="tc">{{ $v['attr'] }}</td>
                                <!-- <td class="tc">{{ $v['cost'] }}</td> -->
                                <td class="tc">{{ $v['sell'] }}</td>
                                <td class="tc">{{ $v['charge'] }}</td>
                                <td class="tc">{{ $v['nums'] }}</td>
                                <!-- <td class="tc">{{ $v['in_nums'] }}</td> -->
                                <td class="tc">{{ $v['shares'] }}</td>
                                <td class="tc">{{ $v['curcle'] }}</td>
                                <td class="tc">{{ $v['start'] }}</td>
                                <td class="tc">{{ $v['end'] }}</td>
                               <td class="tc">
                                    <form class="layui-form " action="">
                                        @if($v['switch'] == 1)
                                            <!-- 开启 -->
                                            @if($v['in_nums'] > 0)
                                                <input type="checkbox" checked name="" lay-skin="switch" lay-filter="switchCy" lay-text="开|关" disabled value="{{ $v['id'] }}">
                                            @else
                                                <input type="checkbox" checked name="" lay-skin="switch" lay-filter="switchCy" lay-text="开|关" value="{{ $v['id'] }}">
                                            @endif
                                            
                                        @else
                                            <!-- 关闭 -->
                                            <input type="checkbox"  name="" lay-skin="switch" lay-filter="switchCy" lay-text="开|关" value="{{ $v['id'] }}">
                                        @endif

                                    </form>
                                </td>
                               <td class="tc">{{$v['created_at']}}</td>
                            
                                <td class="tc">
                                @if($v['switch'] == 2)
                                <button class="layui-btn layui-btn-sm" style="color:white">
                                    <a href="{{url('/admin/group/add?id='.$v['gid'].'&sku_id='.$v['sku_id'].'&page='.$request['page'].'&group_id='.$v['id'])}}" style="color:#fff">编辑</a>
                                </button>
                                @endif
                                <button class="layui-btn layui-btn-sm" style="color:white">
                                    <a href="{{url('/admin/group/cite?id='.$v['id'])}}" style="color:#fff">历史记录</a>
                                </button>
                                </td>
                            </tr>
                        @endforeach
                    @endif
                </tbody>
            </thead>
        </table>
        <!-- 分页 -->
        <div class="sabrosus" >{{ $list->appends(['gid'=>$request['gid'],'gname'=>$request['gname'],'month'=>$request['month']])->links() }}</div>
    </div>

 </div>
 </div>
@endsection
@section('js')
    <script>
        // 删除按钮事件 -- 弹出删除层
        var config = function(url,id,state,title){
            layer.confirm('确定更改('+title+')！', {
                btn: ['确定','取消'] //按钮
            },function(){
                $.post(url,{
                    id: id,state:state,
                },function(data){
                    console.log(data);
                    layer.msg(data.msg);
                    // if(data.code == 1){
                    //     layer.msg('更改成功！');
                    // }else{
                    //     layer.msg('更改失败！');
                    // }
                    location.href = location.href;
                });
            });
        }


        layui.use(['form','laydate'], function(){
            var form = layui.form;
            var laydate = layui.laydate;
            form.render();

            //搜索
            form.on('submit(selectsub)', function(data){
                var gid = $("input[name=sub_gid]").val();
                var gname = $("input[name=sub_gname]").val();
                var month = $("input[name=month]").val();
                location.href = "{{url('admin/group/index')}}"+"?gid=" + gid+ '&gname='+gname+'&month='+month;
                return false;
            });

            //日期时间选择器
            laydate.render({ 
                elem: '#test1'
                ,type: 'datetime'
            });


            //监听指定开关
            form.on('switch(switchCy)', function(data){
                
                var id = data.value;

                if(data.elem.checked){
                    var state = 1;//启用
                }else{
                    var state = 2;//禁用               
                }
                ajax('/admin/group/up_state',{id:id,state:state});
                location.href=location.href;
            });
        });
    </script>
@endsection